import { Body, Controller, Get, Post, Param, Req, Query } from '@nestjs/common';
import { UserService } from './user.service';
import { UserDto, UpdateUserDto, UserPageSearchDto } from '@/dto/user.dto';
import { IsObjectIdPipe } from '@/pipe';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get('info')
  info(@Req() req) {
    return this.userService.findById(req.user.id);
  }

  @Get('queryById/:id')
  findById(@Param('id', IsObjectIdPipe) id: string) {
    return this.userService.findById(id);
  }

  @Post('create')
  create(@Body() user: UserDto) {
    return this.userService.create(user);
  }

  @Post('update')
  update(@Body() user: UpdateUserDto, @Req() req) {
    return this.userService.update(user.id || req.user.id, user);
  }

  @Post('queryList')
  queryList(@Body() userPageSearchDto: UserPageSearchDto) {
    return this.userService.query(userPageSearchDto);
  }
}
